package com.li.tms.core.handler;

import com.li.tms.common.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public R<Boolean> handleException(Exception e, HttpServletRequest request) {
        log.error("全局异常捕获", e);
        if (e instanceof NoHandlerFoundException) {
            return R.error(500, "服务器异常",false,0);
        }
        // 细化处理
        return R.error(500, "服务器异常",false,0);
    }

}
